package it.koutifaris.travianmap.ui.viewstate;

import static it.koutifaris.travianmap.ui.viewstate.NullViewStateListener.nullViewStateListener;
import it.koutifaris.travianmap.ui.viewstate.DynamicViewState.ViewStateListener;

public class ViewStateBuilder {

	public static DynamicViewState dafaultViewState() {
		return new ViewStateImpl(0, 0, 1, DynamicViewState.DEFAULT_SQUARE_WIDTH, nullViewStateListener());
	}

	public static MandatoryParamStep viewStateBuilder() {
		return new BuilderImpl();
	}

	public interface MandatoryParamStep {

		OptionalParamsStep withSquareSize(int squareSize);

		OptionalParamsStep withDefaultSquareSize();

	}

	public interface OptionalParamsStep {
		OptionalParamsStep withPosition(int x, int y);

		OptionalParamsStep withZoom(float zoom);

		OptionalParamsStep withListener(ViewStateListener listener);

		DynamicViewState build();
	}

	private static class BuilderImpl implements MandatoryParamStep, OptionalParamsStep {

		private int x;
		private int y;
		private float zoom;
		private int squareSize;
		private ViewStateListener listener;

		private BuilderImpl() {
			zoom = 1;
			listener = NullViewStateListener.nullViewStateListener();
		}

		@Override
		public OptionalParamsStep withPosition(int x, int y) {
			this.x = x;
			this.y = y;
			return this;
		}

		@Override
		public OptionalParamsStep withZoom(float zoom) {
			this.zoom = zoom;
			return this;
		}

		@Override
		public OptionalParamsStep withListener(ViewStateListener listener) {
			this.listener = listener;
			return this;
		}

		@Override
		public OptionalParamsStep withSquareSize(int squareSize) {
			this.squareSize = squareSize;
			return this;
		}

		@Override
		public OptionalParamsStep withDefaultSquareSize() {
			this.squareSize = DynamicViewState.DEFAULT_SQUARE_WIDTH;
			return this;
		}

		@Override
		public DynamicViewState build() {
			return new ViewStateImpl(x, y, zoom, squareSize, listener);
		}

	}
}
